
// A random number between [min and max)
// With 1 argument it will be [0 to min)
// With no arguments it will be [0 to 1)
export const rand = (min, max) => {
    if (min === undefined) {
        min = 0;
        max = 1;
    } else if (max === undefined) {
        max = min;  
    }
    return min + Math.random() * (max - min);
};

export function fail(msg) {
    // eslint-disable-next-line no-alert
    alert(msg);
}

// 加载着色器代码文件
export async function loadWGSLSoureFile(url) {
    const response = await fetch(url);
    if (!response.ok) {
        throw new Error(`Failed to fetch ${url}`);
    }
    return await response.text();
}

